package com.normal.zbase.impl.arouter

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.annotation.NonNull
import androidx.lifecycle.Lifecycle
import com.didi.drouter.api.DRouter
import com.didi.drouter.api.Extend
import com.didi.drouter.router.IRouterHandler
import com.didi.drouter.router.Request
import com.didi.drouter.router.Result
import com.didi.drouter.store.IRegister
import com.didi.drouter.store.RouterKey

object DRouterUtils {
    fun startAct(path: String?, bundle: Bundle? = null) {
        DRouter.build(path)
            .putExtra("key", bundle) // 自定义参数
            .start()
    }

    /**
     * 事件
     * @param routerKey DRouterPath.DRouterKey
     * @param lifecycle 当前生命周期
     */
    fun register(routerKey: String, lifecycle: Lifecycle, callback: (Request, Result) -> Unit) {
        DRouter.register(
            RouterKey.build(routerKey).setLifecycle(lifecycle)
        ) { request, result ->
            callback.invoke(request, result)
        }
    }

//    fun navigation(pagePath: String?, key1: String?, value1: Int, key2: String?, value2: Int) {
//        DRouter.build(path) //                .putExtra(Extend.START_ACTIVITY_FLAGS, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)   // flag
//            .putExtra(
//                Extend.START_ACTIVITY_FLAGS,
//                Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
//            ) // flag
//            .putExtra("key", bundle) // 自定义参数
//            .start(context) { result -> val r = result.isActivityStarted }
//    }
}